//
//  SwiperScreenVC.m
//  ZZTong
//
//  Created by handpay on 13-5-16.
//  Copyright (c) 2013年 handpay. All rights reserved.
//

#import "HPSwiperViewController.h"
#import <HandPaySwiperModule/HandPaySwiperModule.h>
//#import "HPSwiperService.h"  // mcm

@interface HPSwiperViewController ()
{
//    BOOL continueAnimation;
    
    CGFloat xOffset;
}
@end

@implementation HPSwiperViewController

- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
    self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
    if (self) {
        self.canSave = NO;
        self.showBackButton = NO;
    }
    return self;
}
- (void) startSwipeAnimate
{
    CGRect oFrame = self.cardTagImageView.frame;
    if (0 == xOffset) {
        xOffset = oFrame.origin.x;
    }
    __block UIImageView* tempImageView = self.cardTagImageView;
    [UIView animateWithDuration:2 delay:.5 options:UIViewAnimationCurveEaseInOut | UIViewAnimationOptionAllowUserInteraction animations:^{
        tempImageView.frame = CGRectMake(240, oFrame.origin.y, oFrame.size.width, oFrame.size.height);
    } completion:^(BOOL finished){
        if (finished) {
            tempImageView.frame = CGRectMake(xOffset, oFrame.origin.y, oFrame.size.width, oFrame.size.height);
//            if (continueAnimation) {
            [NSTimer scheduledTimerWithTimeInterval:.5 target:self selector:@selector(startSwipeAnimate) userInfo:nil repeats:NO];
//            }
        }
    }];
}

- (void)restartAnimation
{
    [self startSwipeAnimate];
}

- (void)viewWillAppear:(BOOL)animated{
    [super viewWillAppear:animated];
    [ZZT_UIENG hideNavigationBar:YES];
}
- (void)viewWillDisappear:(BOOL)animated{
    [super viewWillDisappear:animated];
    [ZZT_UIENG hideNavigationBar:NO];
}
- (void)goBack{
    [super goBack];
}

- (IBAction)cancelSwipe
{
    id<HPSwipeServiceProtocal> posService = [HPSwiperContext sharedInstance].avaliableService;
    if (![posService cancelSwiperOperation])
        [[HPUIEngine getInstance] popScreen];
    // mcm
//    if (![SwiperService cancelSwiperOperation])
//    {
//        [HPUIENG popScreen];
//    }
}

- (void)viewDidLoad
{
    [super viewDidLoad];
    
    [self.navigationController setNavigationBarHidden:YES];
    self.navigationItem.hidesBackButton = YES;
   
//    if (HP_Device_iPhone5) {
//        CGRect frame = self.cardTagImageView.frame;
//        frame.origin.y += IPHONE5_ADD_HEIGHT;
//        self.cardTagImageView.frame = frame;
//    }
    
    
    [self startSwipeAnimate];
    
}

- (void)didReceiveMemoryWarning
{
    [super didReceiveMemoryWarning];
}
- (void)viewDidAppear:(BOOL)animated{
    [super viewDidAppear:animated];
}
- (void)viewDidDisappear:(BOOL)animated{
    [super viewDidDisappear:animated];
    [self.navigationController setNavigationBarHidden:NO];
}
- (void)dealloc {
    [_cardTagImageView release];
    [super dealloc];
}
- (void)viewDidUnload {
    [self setCardTagImageView:nil];
    [super viewDidUnload];
}
@end
